#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.

. ../defconfig.sh

docker_skip_rebuild "compass-ci-web"

load_cci_defaults

[[ $BASE_RESULT_URL ]] || BASE_RESULT_URL='https://api.compass-ci.openeuler.org'
[[ $BASE_WEB_BACKEND_URL ]] || BASE_WEB_BACKEND_URL='https://api.compass-ci.openeuler.org/web_backend'
[[ $OAUTH_REDIRECT_URL ]] || OAUTH_REDIRECT_URL='https://compass-ci.openeuler.org/oauth_authorize'

if [ -d "./compass-ci-web" ]; then
	rm -rf ./compass-ci-web
fi

git clone https://gitee.com/openeuler/compass-ci-web
sed -i "s#export const BASEURLRESULT = 'https://api.compass-ci.openeuler.org';#export const BASEURLRESULT = '$BASE_RESULT_URL';#g" ./compass-ci-web/src/utils/baseUrl.js
sed -i "s#const BASEURL = 'https://api.compass-ci.openeuler.org/web_backend';#export const BASEURL = '$BASE_WEB_BACKEND_URL';#g" ./compass-ci-web/src/utils/axios.utils.js
sed -i "s#client_id: \"CLIENT_ID_HERE\"#client_id: \"$OAUTH_CLIENT_ID\"#g" ./compass-ci-web/src/views/user/login.vue
sed -i "s#redirect_uri: \"REDIRECT_URI_HERE\"#redirect_uri: \"$OAUTH_REDIRECT_URL\"#g" ./compass-ci-web/src/views/user/login.vue

docker build --no-cache -t compass-ci-web .

rm -rf ./compass-ci-web

